package com.wxyzz.canteenadmin.goods.stockControl.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wxyzz.canteenadmin.goods.stockControl.mapper.StockControlMapper;
import com.wxyzz.canteenadmin.goods.stockControl.param.StockControlDataParam;
import com.wxyzz.canteenadmin.goods.stockControl.param.StockControlVueParam;
import com.wxyzz.canteenadmin.goods.stockControl.service.StockControlService;
import com.wxyzz.canteenadmin.goods.stockControl.vo.StockControlVo;
import com.wxyzz.canteencommon.exception.CustmerException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class StockControlServiceImpl implements StockControlService {

    @Resource
    private StockControlMapper stockControlMapper;
    @Override
    public PageInfo<StockControlVo> findAllStockControl(StockControlVueParam stockControlVueParam) {
        PageHelper.startPage(stockControlVueParam.getPageNum(),stockControlVueParam.getPageSize());
        List<StockControlVo> stockControlDataParams = stockControlMapper.selectAllStockControl(stockControlVueParam);
        PageInfo<StockControlVo> stockControlDataParamPageInfo = new PageInfo<>(stockControlDataParams);
        return stockControlDataParamPageInfo;
    }

    @Override
    public void saveStockControl(StockControlVueParam stockControlVueParam) {
        if(stockControlVueParam.getOperateType()==null){
            throw new CustmerException("请输入操作类型，操作类型不能为空！");}
        if(stockControlVueParam.getBelongingStoreId()==null){
            throw new CustmerException("请选择所属店铺，所属店铺不能为空！");}
        if(stockControlVueParam.getRemark()==null){
            throw new CustmerException("请输入说明备注，说明备注不能为空！");}
        if(stockControlVueParam.getCreateTime()==null){
            throw new CustmerException("请选择创建时间，所属菜品分类不能为空！");}
        stockControlMapper.insertStockControl(stockControlVueParam);
    }

    @Override
    public StockControlDataParam findStockControlById(int id) {
        StockControlDataParam stockControlDataParam = stockControlMapper.selectStockControlById(id);
        return stockControlDataParam;
    }

    @Override
    public void UpdateStockControl(StockControlVueParam stockControlVueParam) {
        stockControlMapper.UpdateStockControl(stockControlVueParam);
    }

    @Override
    public void deleteStockControlById(int id) {
        stockControlMapper.deleteStockControlById(id);
    }

    @Override
    public void delBatchStockControlById(List<Integer> ids) {
        stockControlMapper.delBatchStockControl(ids);
    }
}
